package main

import (
	"fmt"
	"math"
)

func countGoodRectangles(rectangles [][]int) int {
	max := math.Min(float64(rectangles[0][0]), float64(rectangles[0][1]))
	res := 1
	for i := 1; i < len(rectangles); i++ {
		v := rectangles[i]
		l := math.Min(float64(v[0]), float64(v[1]))
		if l == max {
			res++
		} else if l > max {
			max = l
			res = 1
		}
	}
	return res
}

func main() {
	fmt.Println(countGoodRectangles([][]int{{5, 8}, {3, 9}, {5, 12}, {16, 5}}))
	fmt.Println(countGoodRectangles([][]int{{2, 3}, {3, 7}, {4, 3}, {3, 7}}))

}
